home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
awe2-0_1.lha
/
awe2-0.1
/
Src
/
RCS
/
Thread.cc,v
< prev
next >
Wrap
Text File
|
1989-10-24
|
5KB
|
230 lines
head 3.3;
branch ;
access ;
symbols ;
locks grunwald:3.3; strict;
comment @@;
3.3
date 89.10.24.13.08.37; author grunwald; state Exp;
branches ;
next 3.2;
3.2
date 89.02.20.15.37.47; author grunwald; state Exp;
branches ;
next 3.1;
3.1
date 88.12.20.13.49.21; author grunwald; state Exp;
branches ;
next 1.2;
1.2
date 88.10.30.13.04.41; author grunwald; state Exp;
branches ;
next 1.1;
1.1
date 88.09.18.16.42.30; author grunwald; state Exp;
branches ;
next ;
desc
@@
3.3
log
@*** empty log message ***
@
text
@// This may look like C code, but it is really -*- C++ -*-
//
// Copyright (C) 1988 University of Illinois, Urbana, Illinois
//
// written by Dirk Grunwald (grunwald@@cs.uiuc.edu)
//
#include "CpuMultiplexor.h"
#include "CpuMultiplexorP.h"
#include "Thread.h"
#include "ThreadContainer.h"
#include "assert.h"
const void * UNINITIALIZED = 0;
Thread::Thread(char* name, unsigned stacksize,
ThreadPriority priority, bool xdebug, int checkStack)
: (xdebug), pContext(checkStack, stacksize)
{
threadName = name;
threadPriority = priority;
threadState = RUNNABLE;
cpuAffinity = -1;
pContext.buildReturnFrame(this, voidFuncP(&Thread::startOff));
if (debugFlag) {
cerr << "[create Thread " << name << " at " << hex(long(this)) << "\n";
}
}
Thread::~Thread()
{
makeTerminated();
//
// The destructor for HardwareContext doesn't free the stack space.
// If a thread other than the this thread is calling the destructor,
// we need to reclaim that stack space now.
//
// If the current thread is calling the destructor, it must do so
// by returning from main & the via the delete statement in startOff.
// In that case, we delete the stack in startOff.
//
// It is considered an error for this thread to delete itself in any
// other way (i.e. you can do it, but don't complain about what happens).
//
if ( this != CurrentThread() ) {
void **p = pContext.mallocAt();
delete p;
}
}
void Thread::main()
{
assert2(FALSE, "[Thread] Subclass of thread forgot to specialize main()");
}
void
Thread::startOff()
{
main();
void **p = pContext.mallocAt();
delete this;
ThisCpu -> threadTerminateException( p );
assert2(FALSE,"[Thread] Thread exits main");
}
void Thread::makeTerminated()
{
//
// this doesn't do anything yet. It's not clear it's needed either,
// since most termination-oriented things could happen in the
// destructor.
//
}
void Thread::classPrintOn(ostream& strm)
{
strm << "[Thread:"
<< " " << threadName
<< " pri: " << int(threadPriority)
<< " state: ";
switch (threadState) {
case SUSPENDED:
strm << "SUSPENDED";
break;
case RUNNING:
strm << "RUNNING";
break;
case RUNNABLE:
strm << "RUNNABLE";
break;
case TERMINATED:
strm << "TERMINATED";
break;
case ZOMBIED:
default: strm << "INVALID";
break;
}
strm << "]\n";
strm << pContext << "\n";;
}
@
3.2
log
@Start using Gnu library heaps for schedulers
@
text
@d8 1
a13 1
const double NullTime = -1;
d16 1
a16 1
ThreadPriority priority, int xdebug, int checkStack)
@
3.1
log
@Steay version
@
text
@@
1.2
log
@*** empty log message ***
@
text
@d22 1
@
1.1
log
@Initial revision
@
text
@d1 7
a7 1
#include "HardwareCpu.h"
d15 3
a17 3
Thread::Thread(const char* name, unsigned stacksize,
ThreadPriority priority, int xdebug)
: (xdebug), pContext(1, stacksize)
a30 4
//
// You better hope to god that *this* isn't the current context
// of any executing thread.
//
d33 1
d35 3
a37 4
// If delete is called by a thread
// then
// the raise at this point will switch us to the Hardware context,
// which then calls delete.
d39 3
a41 3
// else if delete is called by the Hardware context
// then the raise simply ``falls through'', since we'll be
// stopping & then restarting the hardware context (right here).
d43 2
a44 5
// The only problem is if someone *else* calls the delete, we need
// to just let them delete it & return. If we raise the exception,
// they'll eventually restart here after the Hardware context
// has deleted the state, and they'll delete it again, causing
// much mahem.
d46 3
a48 2
if ( this == CurrentThread() ) {
ThisCpu -> threadTerminateException( this );
a49 1
makeTerminated();
d61 3
a63 1
ThisCpu -> threadTerminateException( this );
d69 5
d95 2
@